﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using NHibernate.Cfg.MappingSchema;

namespace MVCGen.Generators.Entity {
	public class HbmOneToManyFieldGenerator : ICodeTypeMemberGenerator {
		private String name;
		private HbmOneToMany oneToMany;

		public HbmOneToManyFieldGenerator(String name, HbmOneToMany oneToMany) {
			this.name = name;
			this.oneToMany = oneToMany;
		}

		public CodeTypeMember Generate() {
			
			String type = "System.Collections.Generic.IList`1[[" + oneToMany.@class + "]]";
			CodeMemberField result = new CodeMemberField() {
				Name = name.MakeFieldName(),
				Type = new CodeTypeReference(type),
				Attributes = MemberAttributes.Private,
				InitExpression = new CodeObjectCreateExpression("System.Collections.Generic.List`1[[" + oneToMany.@class + "]]")
			};
			return result;
		}
	}
}
